import time

import jwt as pyjwt

from Novel import settings


class Mjwt:
    def __init__(self, key):
        self.key = key

    def encode(self, payload):
        return pyjwt.encode(payload, self.key, algorithm='HS256')
    def decode(self, token):
        try:
            return pyjwt.decode(token, self.key, algorithms=['HS256'])
        except pyjwt.exceptions.DecodeError:
            return None

myjwt = Mjwt(settings.SECRET_KEY)
# token = myjwt.encode({"userid":"1",'exp':int(time.time()+3600*24*7)})
# print(token)
# print(myjwt.decode(token))
